package com.john.booter.module.option;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.john.booter.annotation.Module;
import com.john.booter.annotation.OptionName;
import com.john.booter.annotation.SubModuleName;
import com.john.booter.domain.entity.Option;
import com.john.booter.domain.entity.Role;
import com.john.booter.module.option.service.OptionService;
import com.john.booter.pagination.DataTable;
import com.john.booter.pagination.Pager;

@SubModuleName(value = "菜单管理", root = Module.user, sort=1)
@RestController
@RequestMapping("/option")
public class OptionCtrl {
	
	@Autowired
	private OptionService service;

	@OptionName("列表-WEB")
	@RequestMapping("/datatable")
	public DataTable<Option> list(
			@RequestParam(value = "start") Integer start,
			@RequestParam(value = "length") Integer pageSize,
			@RequestParam(value = "search[value]") String searchValue,
			@RequestParam(value = "order[0][column]") Integer orderColumn,
			@RequestParam(value = "order[0][dir]") String orderDir,
			@RequestParam(value = "draw") Integer draw) {
		start = ((start == null || start <= 0) ? 0 : start);
		pageSize = (pageSize == null ? Pager.DEFAULT_PAGE_SIZE : pageSize);
		draw = ((draw == null || draw == 0) ? 1 : draw);
		Pager pg = new Pager();
		pg.setStart(start);
		pg.setPageSize(pageSize);
		pg.setSearchValue(searchValue);
		pg.setOrderColumn(orderColumn);
		pg.setOrderDir(orderDir);
		pg.setDraw(draw);
		DataTable<Option> data = service.findDataTable(pg);
		return data;
	}	
}
